import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '@/router/login'
import Home from '@/router/home'

// import User from '@/router/user'
// import Goods from '@/router/goods'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  
  ...Login,
  ...Home,
  // ...Goods,
  // ...User,
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if(to.path !== '/login' &&  !window.localStorage.token){
    next('/login')
  } else {
    next()
  }
})


export default router
